package com.yonyou.pmclouds.completedcatalog.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.completedcatalog.entity.CompletedCatalogBVO;
import com.yonyou.pmclouds.completedcollate.entity.CompletedCollateBVO;
import com.yonyou.pmclouds.completedcollate.mapper.CompletedCollateBVOMapper;

/**
 * 竣工资料目录表体删除时引用校验
 *
 * @author yzx
 * @Date: 2018/5/30 16:21
 */
public class CompletedCatalogBodyDelCheck implements SingleProcessor<CompletedCatalogBVO> {
    private CompletedCollateBVOMapper collateBVOMapper;

    public CompletedCatalogBodyDelCheck(CompletedCollateBVOMapper collateBVOMapper) {
        this.collateBVOMapper = collateBVOMapper;
    }

    @Override
    public void process(CompletedCatalogBVO vo, CompletedCatalogBVO orig) throws BusinessException {
        // 通过资料目录表体pk，查询是否在引用资料中存在，被引用则不能删除
        CompletedCollateBVO[] collateBVOS = collateBVOMapper.queryByCatalogBPk(vo.getPkCompletedCatalogB(), RuntimeEnvironment.getTenantId());
        if (collateBVOS.length > 0) {
            throw new BusinessException("该目录明细已被引用,不能删除!");
        }
    }
}
